﻿package com.tudou.home.newskin.containers
{
    import com.tudou.home.newskin.buttons.*;
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.newskin.model.*;
    import com.tudou.skin.common.button.*;
    import flash.geom.*;
    import gs.*;

    public class PlayListRadioSprite extends RadioButton implements IPlayList, ITransform
    {
        private var listRect:Rectangle;
        private var itemList:Array;
        private var itemListWidth:uint;
        private var goWidth:uint = 600;

        public function PlayListRadioSprite()
        {
            itemList = [];
            listRect = new Rectangle(0, 0, goWidth, NewSkinConsts.PLAYLIST_HEIGHT);
            scrollRect = listRect;
            return;
        }// end function

        private function updateHlr() : void
        {
            if (!checkRoll())
            {
                TweenLite.killTweensOf(listRect, false);
            }
            scrollRect = listRect;
            return;
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            goWidth = param1;
            listRect.width = goWidth;
            listRect.x = index * NewSkinConsts.LISTITEM_WIDTH;
            checkRoll();
            scrollRect = listRect;
            return;
        }// end function

        private function checkRoll() : Boolean
        {
            var _loc_1:* = itemListWidth - listRect.width;
            if (_loc_1 <= 0)
            {
                listRect.x = 0;
                return false;
            }
            if (listRect.x < 0)
            {
                listRect.x = 0;
                return false;
            }
            if (listRect.x > _loc_1)
            {
                listRect.x = _loc_1;
                return false;
            }
            return true;
        }// end function

        public function setIndex(param1:int) : void
        {
            if (itemList == null || itemList.length == 0)
            {
                return;
            }
            activeIndex = param1;
            return;
        }// end function

        public function setPlayList(param1:Array) : void
        {
            var _loc_3:uint = 0;
            var _loc_4:IListItem = null;
            var _loc_5:ListItemButton = null;
            if (param1 == null || param1.length == 0)
            {
                return;
            }
            itemList = param1;
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = NewSkinConsts.LISTITEM_WIDTH;
                _loc_4 = param1[_loc_2] as IListItem;
                _loc_5 = new ListItemButton((_loc_2 + 1) + ") " + _loc_4.videoTitle);
                this.addSelectButton(_loc_5, _loc_3 * _loc_2);
                _loc_2++;
            }
            itemListWidth = this.width;
            return;
        }// end function

        public function rollLeft(param1:Boolean) : void
        {
            var _loc_2:int = 0;
            var _loc_3:String = null;
            if (checkRoll())
            {
                _loc_2 = int(goWidth / NewSkinConsts.LISTITEM_WIDTH) * NewSkinConsts.LISTITEM_WIDTH;
                _loc_3 = _loc_2.toString();
                if (param1)
                {
                    _loc_3 = "-" + _loc_3;
                }
                TweenLite.killTweensOf(listRect, true);
                TweenLite.to(listRect, 0.4, {x:_loc_3, onUpdate:updateHlr});
            }
            scrollRect = listRect;
            return;
        }// end function

        public function getIndex() : int
        {
            return activeIndex;
        }// end function

    }
}
